﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace Shiny.SmartTravel.Data.Local.MyTravel
{
    /// <summary>
    /// An entity to storage the local user's data.
    /// </summary>
    public class Account
    {
        private string datafile = "MyTravel.xml";

        /// <summary>
        /// empty ctor
        /// </summary>
        public Account()
        {
            try
            {
                XDocument xdoc = XDocument.Load(string.Format("{0}\\{1}", Settings.LocalDataFolder, datafile));
                this.Name = (string)xdoc.Element("SmartTravel").Element("Account").Element("Name");
                this.ProvinceName = (string)xdoc.Element("SmartTravel").Element("Account").Element("ProvinceName");
                this.CityName = (string)xdoc.Element("SmartTravel").Element("Account").Element("CityName");
            }
            catch (Exception ex)
            {
                throw new LocalDataException("Account initializing error!", ex);
            }
        }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// gets or sets the province name
        /// </summary>
        public string ProvinceName { get; set; }

        /// <summary>
        /// Gets or sets the city name
        /// </summary>
        public string CityName { get; set; }

        /// <summary>
        /// serialize the data
        /// </summary>
        public void Save()
        {
           //TODO:
        }

        /// <summary>
        /// Return the Name
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return Name;
        }
    }
}
